<?php
$txt = strtr(urldecode(substr($_SERVER['PATH_INFO'], 1)), array("'" => ''));
$id = strtolower(preg_replace('/\W+/u', '-', $txt));

$file = "{$_SERVER['DOCUMENT_ROOT']}/img/badge/btn-{$id}.png";
if (!file_exists($file)) {
  $cmd = "convert {$_SERVER['DOCUMENT_ROOT']}/img/bp/brownie_100x100.png -font {$_SERVER['DOCUMENT_ROOT']}/img/verdanab.ttf -pointsize 40 -gravity Center -fill white -annotate +0-2 '{$txt}' {$file}";
  system($cmd);
}

header('Content-type: image/png');
readfile($file);
